package src.main.java.org.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/*
* ObjectOutputStream(对象字节输出流)
* */
public class Test15 {
    public static void main(String[] args) {

        //创建对象字节输出流
        try (
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:\\JavaLearn\\javaCode\\src\\test9.txt"));
                ObjectInputStream ois = new ObjectInputStream(new FileInputStream("E:\\JavaLearn\\javaCode\\src\\test9.txt"))
        ) {
            User user = new User("admin", "张三", "123456", 23);
            //序列化对象到文件中
            oos.writeObject(user);
            System.out.println("d对象序列化成功");
            User u = (User) ois.readObject();
            System.out.println(u);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
